﻿
@model IEnumerable<Expenses.Domain.Entities.Expense>

@{
    ViewBag.Title = "Index";
}

<h2>Expenses</h2>

 @*<p align="left">
    @Html.ActionLink("Create New", "Create")
    
    @using (Html.BeginForm("Search")) {   
         <p> Title: @Html.TextBox("SearchString") <br />  
         <input type="submit" value="Filter" /></p>
        }
</p>*@

    
<table width="80%" align="center" >
    <tr>
        <th>Name</th>
        <th>Amount</th>
        <th>Average Amount</th>
        <th>Frecuency</th>
        <th>Is Fixed Amount</th>
        <th>Is Active</th>
        <th></th>

    </tr>
    @{ var totalAmount = 0.0;}

    @foreach( var item in Model )
    {
        totalAmount += item.IsActive ? item.Amount : 0;
        
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Amount)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.AverageAmount)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Frecuency)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.IsFixedAmount)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.IsActive)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id=item.Id }) @*|*@
                @*@Html.ActionLink("Details", "Details", new { id=item.Id }) |
                @Html.ActionLink("Delete", "Delete", new { id=item.Id })*@
            </td>
        </tr>
    }
    
    <tr>
        <td colspan="2"/>
        <th>Total amount for active expenses: $</th>
        <th>@totalAmount.ToString("0.00")</th>
    </tr>
</table>
